
import java.io.*;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Scanner;

public class SocketClient {
    public static void main(String [] args){
        Socket socket=null;
        BufferedReader reader=null;
        PrintWriter writer=null;
        try {
            ArrayList<Integer>a=new ArrayList<>();
            for (int i = 0; i < 10; i++) {
                a.add(0);
            }

            socket=new Socket("127.0.0.1", SocketServer.port);

            reader =new BufferedReader(new InputStreamReader(socket.getInputStream()));

            writer =new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())));
            for (int i = 0; i < 10; i++) {
                if(i==4&&a.get(i)==0){
                    Thread.sleep(10000);
                    writer.println("确认号:"+"body" + i);
                    writer.flush();
                    String str=reader.readLine();
                    System.out.println(str);
                    a.set(i,1);
                    i--;
                }
                if(i==7&&a.get(i)==0){
                    writer.println("确认号:");
                    writer.flush();
                    String str=reader.readLine();
                    System.out.println(str);
                    a.set(i,1);
                    i--;
                }
                else {
                    writer.println("确认号:body" + i);
                    writer.flush();
                    String str=reader.readLine();
                    System.out.println(str);
                    a.set(i,1);
                }
            }

            writer.println("end");
            writer.flush();

        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                reader.close();
                writer.close();
                socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
